<template>
	<view class="body">
		
		<paper-left-popup 
		:show="show" @hide="hidepopup" 
		@addfriend="addfriend" @clear="clear">
		</paper-left-popup>
		
		<!-- 小纸条列表 -->
		<block v-for="(item, index) in list" :key="index">
			<paper-list :item="item" :index="index"></paper-list>
		</block>
		
		<!-- 上拉加载 -->
		<loadMore :loadtext="loadtext"></loadMore>
	</view>
</template>

<script>
	import paperList from '../../components/paper/paper-list.vue';
	import loadMore from '../../components/common/load-more.vue';
	import paperLeftPopup from '../../components/paper/paper-left-popup.vue';
	
	export default {
		components:{  
			paperList,
			loadMore,
			paperLeftPopup
		},
		data() {
			return {
				show: false,
				loadtext: "上拉加载更多",
				list:[
					{
						userpic:"../../static/demo/userpic/12.jpg",
						username:"昵称",
						time:"10:21",
						data:"我是信息",
						noreadnum:2,
					},{
						userpic:"../../static/demo/userpic/12.jpg",
						username:"昵称",
						time:"10:21",
						data:"我是信息",
						noreadnum:0,
					},
					{
						userpic:"../../static/demo/userpic/12.jpg",
						username:"昵称",
						time:"10:21",
						data:"我是信息",
						noreadnum:2,
					},
					{
						userpic:"../../static/demo/userpic/12.jpg",
						username:"昵称",
						time:"10:21",
						data:"我是信息",
						noreadnum:2,
					},{
						userpic:"../../static/demo/userpic/12.jpg",
						username:"昵称",
						time:"10:21",
						data:"我是信息",
						noreadnum:0,
					},
					{
						userpic:"../../static/demo/userpic/12.jpg",
						username:"昵称",
						time:"10:21",
						data:"我是信息",
						noreadnum:2,
					},
					{
						userpic:"../../static/demo/userpic/12.jpg",
						username:"昵称",
						time:"10:21",
						data:"我是信息",
						noreadnum:2,
					},{
						userpic:"../../static/demo/userpic/12.jpg",
						username:"昵称",
						time:"10:21",
						data:"我是信息",
						noreadnum:0,
					},
					{
						userpic:"../../static/demo/userpic/12.jpg",
						username:"昵称",
						time:"10:21",
						data:"我是信息",
						noreadnum:2,
					}
				]
			}
		},
		// 监听下拉刷新
		onPullDownRefresh() {
			this.getdata();
		},
		// 上拉加载
		onReachBottom() {
			this.loadmore();
		},
		//监听导航按钮
		onNavigationBarButtonTap(e) {
			
			switch (e.index) {
			case 0:
				this.hidepopup();
				uni.navigateTo({
					url: "../user-list/user-list"
				})
				break;
			case 1:
				this.showpopup();
				break;
			}
		},
		methods: {
			addfriend(){
				this.hidepopup();
			},
			clear(){
				this.hidepopup();
			},
			hidepopup(){
				this.show = false;
			},
			showpopup(){
				this.show = true;
			},
			//获取数据
			getdata(){
				setTimeout(()=>{
					//服务器获取数据
					let arr = [{
							userpic:"../../static/demo/userpic/12.jpg",
							username:"昵称",
							time:"10:21",
							data:"我是信息",
							noreadnum:0,
						},{
							userpic:"../../static/demo/userpic/12.jpg",
							username:"昵称",
							time:"10:21",
							data:"我是信息",
							noreadnum:1,
						},
						{
							userpic:"../../static/demo/userpic/12.jpg",
							username:"昵称",
							time:"10:21",
							data:"我是信息",
							noreadnum:0,
						}];
					//赋值
					this.list = arr;
					//关闭下拉刷新
					uni.stopPullDownRefresh();
				},2000)
			},
			loadmore(){
				if (this.loadtext != "上拉加载更多") {
					return;
				}
				this.loadtext = "加载中";
				setTimeout(() => {
					//获取完成
					let obj = {
							userpic:"../../static/demo/userpic/12.jpg",
							username:"昵称",
							time:"10:21",
							data:"我是信息",
							noreadnum:22,
						};
					this.list.push(obj);
					this.loadtext = "上拉加载更多";
				}, 1000)
			}
		}
	}
</script>

<style>
	.body {
		padding: 0 20upx;
	}

	
</style>
